/*
 * Copyright 2013-2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.blank.white.controller;

import com.blank.black.entity.pojo.BlankConfig;
import com.blank.black.mapper.CommonMapper;
import com.blank.black.service.IBlankConfigService;
import com.blank.white.bussiness.ConfigBusService;
import com.blank.white.common.ResponseEntity;
import com.blank.white.entity.req.ListReq;
import com.blank.white.entity.req.TableInfoReq;
import com.blank.white.entity.vo.TableInfoVO;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
 */
@RestController
@RequestMapping("/blank")
public class BlankController {
    @Resource
    CommonMapper commonMapper;
    @Resource
    private IBlankConfigService blankConfigService;

    @Resource
    private ConfigBusService configBusService;


    /**
     * 查询所有配置好的查询list
     * @return
     * @throws Exception
     */
    @RequestMapping("/list")
    @ResponseBody
    public ResponseEntity<PageInfo<BlankConfig>> list(@RequestParam ListReq listReq) {
        return ResponseEntity.success(configBusService.list(listReq));
    }

    /**
     * 根据id查询配置的查询
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping("/getBlankConfigById")
    @ResponseBody
    public ResponseEntity<BlankConfig> getBlankConfigById(@RequestParam Long id ) {
        return ResponseEntity.success(configBusService.getBlankConfigById(id));
    }
    /**
     * 根据配置Id 删除配置
     * @param blankConfig
     * @return
     */
    @RequestMapping("/editBlankConfig")
    @ResponseBody
    public ResponseEntity<Long> editBlankConfig(@RequestParam BlankConfig blankConfig) {
        return ResponseEntity.success(configBusService.editBlankConfig(blankConfig));
    }

    /**
     * 根据配置Id 删除配置
     * @param id
     * @return
     */
    @RequestMapping("/deleteBlankConfigById")
    @ResponseBody
    public ResponseEntity<Integer> deleteBlankConfigById(@RequestParam Long id) {
        return ResponseEntity.success(configBusService.deleteBlankConfigById(id));
    }

    /**
     * 根据表名查询表字段
     * @param req
     * @return
     */
    @RequestMapping("/listTable")
    @ResponseBody
    public ResponseEntity<PageInfo<TableInfoVO>> listTable(@RequestParam TableInfoReq req) {
        return ResponseEntity.success(configBusService.listTable(req));
    }

    /**
     * 根据表名查询表字段
     * @param req
     * @return
     */
    @RequestMapping("/listTableSchema")
    @ResponseBody
    public ResponseEntity<PageInfo<String>> listTableSchema(@RequestParam TableInfoReq req) {
        return ResponseEntity.success(configBusService.listTableSchema(req));
    }


}
